package com.uxwine.widget;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;

public class ActionDialog extends Dialog implements
		DialogInterface.OnDismissListener
{

	private OnActionListener mOnActionListener;
	public static final int ACTION_CANCEL = -1;
	public static final int ACTION_OK = 0;
	private int mnExitCode = ACTION_CANCEL;
	
	public ActionDialog(Context context)
	{
		super(context);
	}

	public ActionDialog(Context context, int style)
	{
		super(context, style);
	}
	
	public void setOnActionListener(OnActionListener l)
	{
		mOnActionListener = l;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setOnDismissListener(this);
	}

	public void exit(int code)
	{
		mnExitCode = code;
		dismiss();
	}

	public static interface OnActionListener
	{
		public void onExit(int code);
	}

	@Override
	public void onDismiss(DialogInterface dialog)
	{
		if (null != mOnActionListener)
			mOnActionListener.onExit(mnExitCode);
	}
}
